/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bookstore.validator;

import bookstore.util.Utilities;
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;

/**
 *
 * @author Administrator
 */
public class JAXBBookStoreValidationHandler implements ValidationEventHandler {

    protected boolean bIsError = false;
    protected String message = "";
    protected String errorXML = "";

    public String getErrorXML() {
        return errorXML;
    }

    public boolean isbIsError() {
        return bIsError;
    }

    public String getMessage() {
        return message;
    }

    public boolean handleEvent(ValidationEvent event) {
        if (event.getSeverity() == ValidationEvent.FATAL_ERROR ||
                event.getSeverity() == ValidationEvent.ERROR){

            message = event.getMessage();
            bIsError = true;
            errorXML = Utilities.createResponseMessage(message, "NG");
            System.out.println("Error "+ message);
        }
        return true;
    }




}
